{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "运行环境：jupyter notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>distance_from_home</th>\n",
       "      <th>distance_from_last_transaction</th>\n",
       "      <th>ratio_to_median_purchase_price</th>\n",
       "      <th>repeat_retailer</th>\n",
       "      <th>used_chip</th>\n",
       "      <th>used_pin_number</th>\n",
       "      <th>online_order</th>\n",
       "      <th>fraud</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>57.877857</td>\n",
       "      <td>0.31114</td>\n",
       "      <td>1.94594</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   distance_from_home  distance_from_last_transaction  \\\n",
       "0           57.877857                         0.31114   \n",
       "\n",
       "   ratio_to_median_purchase_price  repeat_retailer  used_chip  \\\n",
       "0                         1.94594              1.0        1.0   \n",
       "\n",
       "   used_pin_number  online_order  fraud  \n",
       "0              0.0           0.0    0.0  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd  \n",
    "import numpy as np\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "data=pd.read_csv('card_transdata.csv')\n",
    "data.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "cols = data.shape[1]\n",
    "X = data.iloc[:, 0:cols - 1]\n",
    "y = data.iloc[:, cols - 1:cols]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#划分固定的训练集和测试集\n",
    "from sklearn.model_selection import train_test_split \n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.01,random_state=123)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# XGBoost分类器进行模型训练，代码如下：\n",
    "from xgboost import XGBClassifier\n",
    "\n",
    "\n",
    "param = {\n",
    "    'n_estimators': np.arange(1, 100, 1),\n",
    "    'learning_rate':  np.arange(0.01, 0.1, 0.02)\n",
    "}\n",
    "grid = GridSearchCV(XGBClassifier(), param_grid=param, cv=6,,scoring='accuracy')\n",
    "grid.fit(X_train, y_train)\n",
    "print('最优分类器:', grid.best_params_, '最优分数:', grid.best_score_)  # 得到最优的参数和分值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred = clf.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 1., 0., ..., 0., 0., 1.])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np \n",
    "array = np.array(y_test)\n",
    "y_test=array.reshape(10000)\n",
    "y_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0\n"
     ]
    }
   ],
   "source": [
    "# 查看全部的预测准确度\n",
    "from sklearn.metrics import accuracy_score\n",
    "score = accuracy_score(y_pred, y_test)\n",
    "print(score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[9119    0]\n",
      " [   0  881]]\n"
     ]
    }
   ],
   "source": [
    "#混淆矩阵\n",
    "from sklearn.metrics import confusion_matrix\n",
    "m = confusion_matrix(y_test, y_pred)  # 传入预测值和真实值\n",
    "print(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0（预测不流失）</th>\n",
       "      <th>1（预测流失）</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0（实际不流失）</th>\n",
       "      <td>9119</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1（实际流失）</th>\n",
       "      <td>0</td>\n",
       "      <td>881</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0（预测不流失）  1（预测流失）\n",
       "0（实际不流失）      9119        0\n",
       "1（实际流失）          0      881"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = pd.DataFrame(m, index=['0（实际不流失）', '1（实际流失）'], columns=['0（预测不流失）', '1（预测流失）'])\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "         0.0       1.00      1.00      1.00      9119\n",
      "         1.0       1.00      1.00      1.00       881\n",
      "\n",
      "    accuracy                           1.00     10000\n",
      "   macro avg       1.00      1.00      1.00     10000\n",
      "weighted avg       1.00      1.00      1.00     10000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import classification_report\n",
    "print(classification_report(y, y_pred))  # 传入预测值和真实值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.00331165, 0.996673  , 0.00331165, ..., 0.00331165, 0.00331165,\n",
       "       0.996673  ], dtype=float32)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_pred_proba = clf.predict_proba(X_test) \n",
    "y_pred_proba[:,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.计算ROC曲线需要的假警报率（fpr）、命中率（tpr）及阈值（thres）\n",
    "from sklearn.metrics import roc_curve\n",
    "fpr, tpr, thres = roc_curve(y_test, y_pred_proba[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>阈值</th>\n",
       "      <th>假警报率</th>\n",
       "      <th>命中率</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.996748</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.996748</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.006810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.996673</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.698070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.996631</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.889898</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.996302</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.921680</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         阈值  假警报率       命中率\n",
       "0  1.996748   0.0  0.000000\n",
       "1  0.996748   0.0  0.006810\n",
       "2  0.996673   0.0  0.698070\n",
       "3  0.996631   0.0  0.889898\n",
       "4  0.996302   0.0  0.921680"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.查看假警报率（fpr）、命中率（tpr）及阈值（thres）\n",
    "a = pd.DataFrame()  # 创建一个空DataFrame \n",
    "a['阈值'] = list(thres)\n",
    "a['假警报率'] = list(fpr)\n",
    "a['命中率'] = list(tpr)\n",
    "a.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.\n",
      "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:211: RuntimeWarning: Glyph 26354 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:211: RuntimeWarning: Glyph 32447 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.\n",
      "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:180: RuntimeWarning: Glyph 26354 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:180: RuntimeWarning: Glyph 32447 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEWCAYAAABrDZDcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAASaklEQVR4nO3de5DdZX3H8ffHxHgFLyR2kAQTa2iNtgVni6JWcfASGE3ajjowpV6GirXFjtVxxNGCg51pq7W2Tmk1Veqlo4h2lIwTTVvFoo5B1iFQE8SuiLKCw4oU7yL67R/noMeTs5sl2d857j7v18zO/C7POef7ZHfz2ef53VJVSJLadY9JFyBJmiyDQJIaZxBIUuMMAklqnEEgSY0zCCSpcQaBJDVu9aQLkCYpyQ3ArwA/Ab4LfAw4p6q+29//eOAvgd8GfgpcDryqqvYPvMeRwAXA7wMPBr4BfKT/uicArxzx0buAfwPeO2LfzVX1nCXonrQojggkeFZV3R84HjgBeDVAkpOA/wAuBR4KbAKuBj6T5OH9NmuAjwOPArYCRwKPB24FTgSOBl5XVU+866vf7jjgvsAnB/f192dM/ZYAg0D6mar6BrCbXiAAvAF4d1X9Q1V9p6q+VVWvBfYAr+u3eR5wLPB7VbW/qn5aVbdU1eurate4+y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zgXsCVNVb6R0HOQ2YAb4PvPCwP3MZ/3tJkpbASpwakiTdDQaBJDXOIJCkxhkEktQ4g0CSGmcQSIuU5CdJ9g58bUxycpLb+3e+vDbJ+f22g9u/mORvJ12/NJ8Vdx2B1KEfVNXxgxv6tzD/VFU9M8n9gL1J7rq30V3b7wNcleRDVfWZ8ZYsHZwjAmmJVNX3gM8Dvzq0/QfAXg7zxmBSVwwCafHuMzAt9KHhnUmOondPo31D2x9E734/l4+nTOnucWpIWrwDpob6fifJVcBPgb/u3wLh5P72a4Bf62//xhhrlRbNIJAO36eq6pnzbU9yHPDp/jGCveMuTjoYp4akjlXVl4C/Al416VqkUQwCaTzeCjwpyaZJFyIN8+6jktQ4RwSS1DiDQJIaZxBIUuMMAklqnEEgSY0zCCSpcQaBJDXu/wEzOhBmaVuaGgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 3.绘制ROC曲线\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  # 设置中文\n",
    "plt.plot(fpr, tpr)  # 通过plot()函数绘制折线图\n",
    "plt.title('ROC曲线')  # 添加标题，注意如果要写中文，需要在之前添加一行代码：plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.xlabel('FPR')  # 添加X轴标签\n",
    "plt.ylabel('TPR')  # 添加Y轴标\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.求出模型的AUC值\n",
    "from sklearn.metrics import roc_auc_score\n",
    "score = roc_auc_score(y_test, y_pred_proba[:,1])\n",
    "score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
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TsyT7/92RuyvJUzna/DzwZ2et7S8q/hodZ2TnQLS1yr8x3lN4/253ZvxuAfRFxQf7GEXFzdsZ+DbBRUk+bQv0mvQGBr6thVeVj6FavDpC5zGxiEfE7YJek6+HYvWn/Y/bxFyLi1YhYCvyW3pc9zfcqcLmksdkPWhcBP8tr8yJwraQWSaOAPxxIrWaD4Rm61aWI2Ju9i9Fm4CCZq/Ql8VXgryX9OTCMzG3B3gC+L2kKmdn3c9nn+szks/t+V9IdwAvZ9qsj4um8Nv8iaRWZqwb+Cvj5QMdoNlC+2qKZWUr4kIuZWUo40M3MUsKBbmaWEg50M7OUcKCbmaWEA93MLCUc6GZmKfH/Abionrh8GYRoAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(thres[1:], tpr[1:])\n",
    "plt.plot(thres[1:], fpr[1:])\n",
    "plt.plot(thres[1:], tpr[1:] - fpr[1:])\n",
    "plt.xlabel('threshold')\n",
    "plt.legend(['tpr', 'fpr', 'tpr-fpr'])\n",
    "plt.gca().invert_xaxis() \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
